package hotel.service.impl;

import hotel.service.IHotelReviewService;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import common.dao.HotelOrderDAO;
import common.dao.ReviewDAO;
import common.pojo.Review;


@Scope("prototype")
@Service
public class HotelReviewService implements IHotelReviewService {
	@Resource
	private ReviewDAO reviewDAO;
	@Resource
	private HotelOrderDAO orderDAO;

	
	public List<Review> find(String where,int start, int limit,String orderbys) {
		List<Review> review= reviewDAO.find(where,start, limit, orderbys);
		for (int i = 0, length = review.size(); i < length; i++) {
			review.get(i).setRoomName(
					orderDAO.findInfoById(review.get(i).getOrderId())
							.getRoomName());
		}	
		return review;
	}
	
	public List<Review> findList(String where,int start, int limit,String orderbys) {
		List<Review> review= reviewDAO.findList(where,start, limit, orderbys);
		for (int i = 0, length = review.size(); i < length; i++) {
			review.get(i).setRoomName(
					orderDAO.findInfoById(review.get(i).getOrderId())
							.getRoomName());
		}	
		return review;
	}

	public int getCount(String where){
		return reviewDAO.getCount(where);
	}

	
	public Review find(int id){
		return reviewDAO.find(id);
	}
	
	
	public boolean verify(String ids) {
		String[] id=ids.split(",");
		for(int i=0;i<id.length;i++)
		{
			reviewDAO.verify(Integer.parseInt(id[i]));
		}
		return true;
	}

	public boolean delete(String ids) {
		String[] id = StringUtils.split(ids,",");
		for(int i=0;i<id.length;i++){
			reviewDAO.delete(Integer.valueOf(id[i]));
		}
		return true;
	}

	public void save(int orderid, Review review,String userName) {
		reviewDAO.save(orderid,review,userName);
		
	}


}
